// pages/music/music.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    res:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options);
    wx.request({
      url: 'http://192.168.4.18:3000/top/playlist?cat=%E5%8D%8E%E8%AF%AD',
      data: {},
      method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT
      // header: {}, // 设置请求的 header
      success: res=>{
        // success
        console.log(res.data.playlists);

        // 播放数
        res.data.playlists.forEach(element => {
          var res =  this.deal(element.playCount);
          element.playCount = res;
        });
        this.setData({
          res:res.data.playlists
        });
      }
    })
  },
  handleToggle(event){
    let {id} = event.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/detail/detail?id=${id}`
    });
    /* location.href */
  },
  deal(num){
    
    if(num>=100000000){
      num = Math.floor(num/100000000)+"亿"
    }else if(num>=10000){
      num = Math.floor(num/10000)+"万"
    }
    return num;
  }
})